// pages/netCase/opinion/opinion.js
import ecfsConfig from '../../../config/ecfs.config.js'
import { checkedOpinionKinds } from '../../../js/netCase/evidence/evidenceData.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checkedOpinionKinds,
    evidenceId: '',
    evidenceObjection: '',
    opinion: '',
    items: [
      { name: '1', value: '质疑真实性' },
      { name: '2', value: '质疑合法性' },
      { name: '3', value: '质疑关联性' }
    ]
  },
  opinion: function (e) {
    this.setData({
      opinion: e.detail.value
    })
  },
  checkOpinion: function (e) {
    Object.keys(this.data.checkedOpinionKinds).forEach(key => {
      if (this.data.checkedOpinionKinds[key].kind.toString() === e.detail.value.toString()) {
        this.setData({
          evidenceObjection: this.data.checkedOpinionKinds[key].status
        })
      }
    })
  },
  sendOpinion() {
    if (this.data.opinion != '') {
      let that = this
      wx.request({
        url: ecfsConfig.IS_PRODUCTION ? (ecfsConfig.SERVER_DOMAIN + ecfsConfig.SEND_OPINION_URL) : (ecfsConfig.SERVER_DOMAIN + ecfsConfig.RAP_URL_PREFIX + ecfsConfig.SEND_OPINION_URL),
        data: {
          evidenceId: this.data.evidenceId,
          evidenceObjection: this.data.evidenceObjection,
          opinion: this.data.opinion
        },
        method: 'POST',
        success: function (res) {
          if (res.data.code === 200) {
            wx.navigateTo({
              url: '../evidenceInfo/evidenceInfo'
            })
          } else {
            wx.showToast({
              title: '服务器错误',
              icon: 'none',
              duration: 1000
            })
          }
        },
        fail: function (res) {
          console.log(res.data);
          console.log('is failed')
        }
      })
    } else {
      wx.showToast({
        title: '请输入质证意见',
        icon: 'none',
        duration: 1000
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      evidenceid: options.evidenceid
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})